/*
 * BplusTreeFile_test.cpp
 *
 *  Created on: Oct 31, 2012
 *      Author: m
 */

#include "BPlusTreeFile.h"

#define BLOCKSIZE 1000

int main(){

    std::unique_ptr<BPlusTreeFile> testFile;

    testFile.reset( new BPlusTreeFile("test.bpt",BLOCKSIZE,true) );

    node_ptr testPtr1,testPtr2, testPtr3,
        testPtr4,testPtr5,testPtr6,testPtr7;

    cerr << "Realizando pruebas Básicas" << endl;
    testPtr1 = testFile->getNewNode(0);
    testFile->saveNode(testPtr1);
    testPtr2 = testFile->getNewNode(1);
    testFile->saveNode(testPtr2);
    testPtr3 = testFile->getNode(testPtr1->getNodeID());

    cerr<<"Node 1"<<endl;
    cerr<<"\t getLevel() "  <<((testPtr1->getLevel() == 0)? "OK":"FAIL")<<endl;
//    cout<<"\t getOrder() "  <<((testPtr1->getOrder() == ORDER)?"OK":"FAIL")<<endl;
    cerr<<"Node 2"<<endl;
    cerr<<"\t getLevel() "  <<((testPtr2->getLevel() == 1)? "OK":"FAIL")<<endl;
//    cout<<"\t getOrder() "  <<((testPtr2->getOrder() == ORDER)?"OK":"FAIL")<<endl;
    cerr<<endl<<"\t getNodeID("<<testPtr1->getNodeID()<<") "<<((testPtr3->getNodeID() == testPtr1->getNodeID())? "OK":"FAIL")<<endl<<endl;

    cerr << "Reabriendo el archivo" << endl;
    testFile.reset( new BPlusTreeFile("test.bpt") );
    testPtr4 = testFile->getNode( testPtr1->getNodeID() );
    testPtr5 = testFile->getNode( testPtr2->getNodeID() );

    cerr<<endl<<"\t getNodeID("<<testPtr1->getNodeID()<<") "<<((testPtr4->getNodeID() == testPtr1->getNodeID())? "OK":"FAIL")<<endl<<endl;
    cerr<<endl<<"\t getNodeID("<<testPtr2->getNodeID()<<") "<<((testPtr5->getNodeID() == testPtr2->getNodeID())? "OK":"FAIL")<<endl<<endl;

    cerr << "Reabriendo el archivo con blockSize Inválido" << endl;
    testFile.reset( new BPlusTreeFile("test.bpt",BLOCKSIZE + 1000) );
    testPtr6 = testFile->getNode( testPtr1->getNodeID() );
    testPtr7 = testFile->getNode( testPtr2->getNodeID() );

    cerr<<endl<<"\t getNodeID("<<testPtr1->getNodeID()<<") "<<((testPtr6->getNodeID() == testPtr1->getNodeID())? "OK":"FAIL")<<endl<<endl;
    cerr<<endl<<"\t getNodeID("<<testPtr2->getNodeID()<<") "<<((testPtr7->getNodeID() == testPtr2->getNodeID())? "OK":"FAIL")<<endl<<endl;

    return 0;

}
